home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / Chip_2004-07_cd1.bin / oddech / pipe / PipeDownDemo.exe / 2057 / SHOCKWAVE / 132 / 00032_Ins Behaviour.ls < prev    next >
Encoding:
Text File  |  2004-05-25  |  20.2 KB  |  698 lines

  1. property pStraights, pBends, pBoxes, pBoxesPos, pStraightsReset, pBendsReset, pStraightsComplete, pBendsComplete, hk, pBall, pBallRB, pPipes, pArrow, pCup, pGap, pNormalShader, pGlowShader, pNoHks, pTime, pTimeGone, pPipeActive, pPipeTotal, pPipesUsed, pAdjSlots, pLandCount, pStuckCount, pFadeState, pLevelScore, pPipeScore, pMovesLeft, pMovesMax, pLevelFailure, leftkey, rightkey, downkey, upkey, spacekey, dcam, cam, dcamCenter, pCamZoom, pCamRotate, pRotX, pRotY, pMousePrevX, pMousePrevY, pRotations, pSucker, pLoaderData, pCursorLoc, pLocNum, pCursorX, pCursorY, pCursorX2, pCursorY2, pCursorTime, pWaits, pWaitNum, pWaitStart, pInsNum, pInsAction, pActionNum, pActions, pStartTime
  2. global w3d, gKeyOn, gGameMode, gLevel, gScore, gSkillMode, gPrevLevel
  3.  
  4. on beginSprite me
  5.   gPrevLevel = gLevel
  6.   gLevel = 1
  7.   w3d = sprite(2).member
  8.   w3d.resetWorld()
  9.   hk = member(1)
  10.   hk.Initialize(w3d, 1, 0.025)
  11.   pStraights = []
  12.   pBends = []
  13.   pBoxes = []
  14.   pBoxesPos = []
  15.   pRotations = [vector(0, 0, 90), vector(90, 0, 0), vector(0, 0, 0), vector(0, 90, 0), vector(0, 180, 0), vector(0, 270, 0), vector(180, 0, 0), vector(180, 90, 0), vector(0, 0, 180), vector(180, 270, 0), vector(0, 270, 90), vector(90, 0, 0), vector(270, 0, 0), vector(0, 90, 90)]
  16.   gLevel = 1
  17.   loadLevel()
  18.   getCompleteLevels()
  19.   setupGame()
  20.   setupObjects(me)
  21.   setupCamera()
  22. end
  23.  
  24. on loadLevel
  25.   txt = member("Levels").text.line[gLevel]
  26.   if txt.word.count < 8 then
  27.     alert("Error loading level")
  28.     return 
  29.   end if
  30.   pLoaderData = []
  31.   pLoaderData.add(vector(float(txt.word[4]), float(txt.word[5]), float(txt.word[6])))
  32.   pLoaderData.add(vector(float(txt.word[7]), float(txt.word[8]), float(txt.word[9])))
  33.   pLoaderData.add(integer(txt.word[3]))
  34.   n = 10
  35.   lim = 3
  36.   if gLevel > 30 then
  37.     lim = 4
  38.   end if
  39.   m = w3d.model[1]
  40.   t = m.getWorldTransform()
  41.   repeat with x = 1 to lim
  42.     repeat with y = 1 to lim
  43.       repeat with z = 1 to lim
  44.         i = integer(txt.word[n])
  45.         n = n + 1
  46.         if (i > 0) and (i < 4) then
  47.           m.transform = transform()
  48.           m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  49.           if i <> 1 then
  50.             m.rotate(pRotations[i - 1])
  51.           end if
  52.           pStraights.add(m.transform.duplicate())
  53.           next repeat
  54.         end if
  55.         if (i > 3) and (i < 16) then
  56.           m.transform = transform()
  57.           m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  58.           m.rotate(pRotations[i - 1])
  59.           pBends.add(m.transform.duplicate())
  60.           next repeat
  61.         end if
  62.         if i = 16 then
  63.           pBoxesPos.add(vector((x - 1) * 16, (y - 1) * -16, (z - 1) * -16))
  64.         end if
  65.       end repeat
  66.     end repeat
  67.   end repeat
  68.   m.transform = t
  69. end
  70.  
  71. on getCompleteLevels
  72.   txt = member("LevelsComplete").text.line[gLevel]
  73.   if txt.word.count < 8 then
  74.     alert("Error loading complete level")
  75.     return 
  76.   end if
  77.   pStraightsComplete = []
  78.   pBendsComplete = []
  79.   n = 10
  80.   lim = 3
  81.   if gLevel > 30 then
  82.     lim = 4
  83.   end if
  84.   m = w3d.model[1]
  85.   t = m.getWorldTransform()
  86.   repeat with x = 1 to lim
  87.     repeat with y = 1 to lim
  88.       repeat with z = 1 to lim
  89.         i = integer(txt.word[n])
  90.         n = n + 1
  91.         if (i > 0) and (i < 4) then
  92.           m.transform = transform()
  93.           m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  94.           if i <> 1 then
  95.             m.rotate(pRotations[i - 1])
  96.           end if
  97.           pStraightsComplete.add(m.transform.duplicate())
  98.           next repeat
  99.         end if
  100.         if (i > 3) and (i < 16) then
  101.           m.transform = transform()
  102.           m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  103.           m.rotate(pRotations[i - 1])
  104.           pBendsComplete.add(m.transform.duplicate())
  105.         end if
  106.       end repeat
  107.     end repeat
  108.   end repeat
  109.   m.transform = t
  110. end
  111.  
  112. on parseTransform txt
  113.   valid = "[]-1234567890,."
  114.   txtLen = txt.length
  115.   repeat with i = 1 to txtLen
  116.     if valid contains txt.char[i..i] then
  117.       next repeat
  118.     end if
  119.     delete txt.char[i..i]
  120.     i = i - 1
  121.     txtLen = txtLen - 1
  122.   end repeat
  123.   return txt
  124. end
  125.  
  126. on setupObjects me
  127.   pGlowShader = w3d.shader("GlowGlassShader")
  128.   pNormalShader = w3d.shader("GlassShader")
  129.   pNormalShader.blend = 50
  130.   pGlowShader.blend = 70
  131.   hk.gravity = vector(0, -200, 0)
  132.   pBall = w3d.model("Ball")
  133.   pCup = w3d.model("Cup")
  134.   pSucker = w3d.model("BallSucker")
  135.   pBall.worldPosition = pLoaderData[1]
  136.   pCup.worldPosition = pLoaderData[2]
  137.   pSucker.transform.position = pBall.worldPosition
  138.   if gLevel > 30 then
  139.     w3d.model("BoxOutline").scale(1.33329999999999993, 1.33329999999999993, 1.33329999999999993)
  140.   end if
  141.   pPipes = []
  142.   num = 1
  143.   repeat with i = 1 to pStraights.count
  144.     w3d.model("Pipe_Straight(Glass)").clone("Pipe" & num)
  145.     m = w3d.model("Pipe" & num)
  146.     m.transform = pStraights[i]
  147.     pPipes.add(m)
  148.     num = num + 1
  149.   end repeat
  150.   repeat with i = 1 to pBends.count
  151.     w3d.model("Pipe_Bend(Glass)").clone("Pipe" & num)
  152.     m = w3d.model("Pipe" & num)
  153.     m.transform = pBends[i]
  154.     pPipes.add(m)
  155.     num = num + 1
  156.   end repeat
  157.   pPipeTotal = num - 1
  158.   w3d.deleteModel("Pipe_Straight(Glass)")
  159.   w3d.deleteModel("Pipe_Bend(Glass)")
  160.   w3d.deleteModel("Glow_Bend(Glass)")
  161.   w3d.deleteModel("Glow_Straight(Glass)")
  162.   pPipeActive = pPipes[1]
  163.   pPipeActive.shaderList[getShaderNum(pPipeActive)] = pGlowShader
  164.   pBoxes = []
  165.   repeat with i = 1 to pBoxesPos.count
  166.     w3d.model("BoxChrome").clone("BoxChrome" & i)
  167.     m = w3d.model("BoxChrome" & i)
  168.     m.transform.position = pBoxesPos[i]
  169.     pBoxes.add(m)
  170.   end repeat
  171.   w3d.deleteModel("BoxChrome")
  172.   pArrow = [w3d.model("Arrow")]
  173.   pArrow[1].scale(1.5)
  174.   pArrow[1].pointAtOrientation = [vector(0, 1, 0), vector(1, 0, 0)]
  175.   repeat with i = 1 to 5
  176.     b = w3d.model("Arrow").clone("Arrow" & i)
  177.     b.pointAtOrientation = [vector(0, 1, 0), vector(1, 0, 0)]
  178.     pArrow.add(b)
  179.   end repeat
  180.   setArrows()
  181.   bf = w3d.newTexture("BlackFade", #fromCastMember, member("black"))
  182.   w3d.camera[1].addOverlay(bf, point(0, 0), 0)
  183.   w3d.camera[1].overlay[1].scale = 840
  184.   w3d.camera[1].overlay[1].blend = 100
  185.   bf = w3d.newTexture("Cursor", #fromCastMember, member("cursor"))
  186.   w3d.camera[1].addOverlay(bf, point(0, 0), 0)
  187.   w3d.camera[1].overlay[2].blend = 100
  188.   w3d.camera[1].overlay[2].loc = pCursorLoc[1]
  189. end
  190.  
  191. on setPipes setType
  192.   if setType = "start" then
  193.     straights = pStraights
  194.     bends = pBends
  195.   else
  196.     if setType = "complete" then
  197.       straights = pStraightsComplete
  198.       bends = pBendsComplete
  199.     else
  200.       if setType = "back" then
  201.         straights = pStraightsReset
  202.         bends = pBendsReset
  203.       end if
  204.     end if
  205.   end if
  206.   pStraightsReset = []
  207.   pBendsReset = []
  208.   num = 1
  209.   repeat with i = 1 to pStraights.count
  210.     m = w3d.model("Pipe" & num)
  211.     pStraightsReset[i] = m.getWorldTransform()
  212.     m.transform = straights[i]
  213.     num = num + 1
  214.   end repeat
  215.   repeat with i = 1 to pBends.count
  216.     m = w3d.model("Pipe" & num)
  217.     pBendsReset[i] = m.getWorldTransform()
  218.     m.transform = bends[i]
  219.     num = num + 1
  220.   end repeat
  221.   setArrows()
  222. end
  223.  
  224. on getShaderNum pipe
  225.   if string(pipe.resource.name).length < 20 then
  226.     return 2
  227.   else
  228.     return 1
  229.   end if
  230. end
  231.  
  232. on makeHK
  233.   pPipeActive.shaderList[getShaderNum(pPipeActive)] = pNormalShader
  234.   repeat with i = 1 to 6
  235.     pArrow[i].transform.position = vector(0, 1000, 0)
  236.   end repeat
  237.   pNoHks = ["Ball", "Marker"]
  238.   pBall.addModifier(#meshDeform)
  239.   pBallRB = hk.makeMovableRigidBody(pBall.name, 1, 1, #sphere)
  240.   pBallRB.restitution = 0.20000000000000001
  241.   pBallRB.friction = 0.80000000000000004
  242.   pBallRB.linearVelocity = vector(0, 0, 0)
  243.   pBallRB.angularVelocity = vector(0, 0, 0)
  244.   pCup.addModifier(#meshDeform)
  245.   rb = hk.makeFixedRigidBody(pCup.name, 0)
  246.   rb.restitution = 0.0
  247.   rb.friction = 0.80000000000000004
  248.   repeat with i = 1 to pPipes.count
  249.     pPipes[i].addModifier(#meshDeform)
  250.     rb = hk.makeFixedRigidBody(pPipes[i].name, 0)
  251.     rb.restitution = 0.0
  252.     rb.friction = 0.80000000000000004
  253.   end repeat
  254.   pGap = []
  255.   m = w3d.model[1]
  256.   t = m.getWorldTransform()
  257.   lim = 3
  258.   if gLevel > 30 then
  259.     lim = 4
  260.   end if
  261.   repeat with x = 1 to lim
  262.     repeat with y = 1 to lim
  263.       repeat with z = 1 to lim
  264.         m.transform = transform()
  265.         m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
  266.         foundPipe = 0
  267.         repeat with p in pPipes
  268.           dPipe = m.worldPosition.distanceTo(p.worldPosition)
  269.           if dPipe < 5 then
  270.             foundPipe = 1
  271.           end if
  272.         end repeat
  273.         if not foundPipe then
  274.           pGap.add(m.worldPosition)
  275.         end if
  276.       end repeat
  277.     end repeat
  278.   end repeat
  279.   m.transform = t
  280.   soundFX("drop", 3, 255)
  281.   mend = member("roll").duration
  282.   sound(2).volume = 0
  283.   sound(2).play([#member: member("roll"), #startTime: 0, #endTime: mend, #loopStartTime: 0, #loopEndTime: mend, #loopCount: 1000])
  284.   gGameMode = #drop
  285. end
  286.  
  287. on setupGame
  288.   pTime = the timer
  289.   pAdjSlots = [vector(16, 0, 0), vector(-16, 0, 0), vector(0, 16, 0), vector(0, -16, 0), vector(0, 0, 16), vector(0, 0, -16)]
  290.   pLandCount = 0
  291.   pStuckCount = 0
  292.   pLevelScore = 0
  293.   pPipeScore = 0
  294.   pMovesMax = pLoaderData[3]
  295.   if gSkillMode < 3 then
  296.     pMovesLeft = pMovesMax * 2
  297.   else
  298.     pMovesLeft = pMovesMax
  299.   end if
  300.   pPipesUsed = 0
  301.   pFadeState = #up
  302.   pLevelFailure = 0
  303.   setVariable(sprite(1), "score", string(gScore))
  304.   setVariable(sprite(1), "level", string(gLevel))
  305.   setVariable(sprite(1), "movesLeft", string(pMovesLeft))
  306.   moveFlash("ins")
  307.   pActionNum = 1
  308.   pActions = [#waitAction, #cursor, #waitAction, #cursor, #waitAction, #cursor, #waitAction, #changePipe, #waitAction, #cursor, #waitAction, #movePipe, #waitAction, #cursor, #waitAction, #insAction, #waitAction, #reset, #waitAction, #insAction, #waitAction, #hint, #waitAction, #insAction, #waitAction, #continue, #waitAction, #cursor, #waitAction, #movePipe, #waitAction, #cursor, #waitAction, #insAction, #waitAction, #dropbutton]
  309.   pWaits = [17, 4, 3, 1, 7, 2, 7, 0, 100, 4, 100, 3, 100, 100, 1, 3, 0, 100]
  310.   pWaitNum = 1
  311.   pWaitStart = the timer
  312.   pLocNum = 2
  313.   pCursorLoc = [point(300, 400), point(100, 600), point(400, 601), point(650, 340), point(640, 580), point(838, 620), point(500, 390), point(838, 460)]
  314.   pInsNum = 1
  315.   pInsAction = ["reset", "hint", "continue", "dropball"]
  316.   gGameMode = pActions[pActionNum]
  317.   pStartTime = the timer
  318.   gMenuCalled = 0
  319.   flashSFX()
  320. end
  321.  
  322. on enterFrame
  323.   if ((the timer - pStartTime) / 60.0) > 3.70000000000000018 then
  324.     pStartTime = the timer + (60 * 10000)
  325.     mend = member("InsMusic").duration
  326.     sound(7).volume = 50
  327.     sound(7).play([#member: member("InsMusic"), #startTime: 2500, #endTime: mend, #loopStartTime: 0, #loopEndTime: mend, #loopCount: 1000])
  328.   end if
  329.   prevMode = gGameMode
  330.   if gGameMode = #dropbutton then
  331.     makeHK()
  332.     gGameMode = #drop
  333.   else
  334.     if gGameMode = #drop then
  335.       checkDrop()
  336.     else
  337.       if gGameMode = #waitAction then
  338.         waitAction()
  339.       else
  340.         if gGameMode = #insAction then
  341.           insAction()
  342.         else
  343.           if gGameMode = #cursor then
  344.             moveCursor()
  345.           else
  346.             if gGameMode = #changePipe then
  347.               changePipe()
  348.             else
  349.               if gGameMode = #movePipe then
  350.                 movePipe()
  351.               else
  352.                 if gGameMode = #reset then
  353.                   setPipes("start")
  354.                   pActionNum = pActionNum + 2
  355.                   pWaitNum = pWaitNum + 1
  356.                   gGameMode = pActions[pActionNum]
  357.                   if gGameMode = #waitAction then
  358.                     pWaitStart = the timer
  359.                   end if
  360.                 else
  361.                   if gGameMode = #hint then
  362.                     setPipes("complete")
  363.                     put "CALLED COMPLETE************"
  364.                     pActionNum = pActionNum + 2
  365.                     pWaitNum = pWaitNum + 1
  366.                     gGameMode = pActions[pActionNum]
  367.                     if gGameMode = #waitAction then
  368.                       pWaitStart = the timer
  369.                     end if
  370.                   else
  371.                     if gGameMode = #hintend then
  372.                       setPipes("start")
  373.                       pActionNum = pActionNum + 2
  374.                       pWaitNum = pWaitNum + 1
  375.                       gGameMode = pActions[pActionNum]
  376.                       if gGameMode = #waitAction then
  377.                         pWaitStart = the timer
  378.                       end if
  379.                     else
  380.                       if gGameMode = #cursor28 then
  381.                         pActionNum = pActionNum + 1
  382.                         pWaitNum = pWaitNum + 1
  383.                         gGameMode = pActions[pActionNum]
  384.                         pCursorX = (pCursorLoc[pLocNum][1] - pCursorLoc[pLocNum - 1][1]) / 70.0
  385.                         pCursorY = (pCursorLoc[pLocNum][2] - pCursorLoc[pLocNum - 1][2]) / 70.0
  386.                         pCursorX2 = 0
  387.                         pCursorY2 = 0
  388.                         if gGameMode = #waitAction then
  389.                           pWaitStart = the timer
  390.                         end if
  391.                       else
  392.                         if gGameMode = #finish then
  393.                           if pFadeState <> #down then
  394.                             pFadeState = #down
  395.                           end if
  396.                         end if
  397.                       end if
  398.                     end if
  399.                   end if
  400.                 end if
  401.               end if
  402.             end if
  403.           end if
  404.         end if
  405.       end if
  406.     end if
  407.   end if
  408.   updateCamera()
  409.   if pFadeState <> #none then
  410.     fadeLevel()
  411.   end if
  412.   pCursorTime = the milliSeconds
  413. end
  414.  
  415. on waitAction
  416.   if ((the timer - pWaitStart) / 60.0) > pWaits[pWaitNum] then
  417.     pActionNum = pActionNum + 1
  418.     pWaitNum = pWaitNum + 1
  419.     gGameMode = pActions[pActionNum]
  420.     if gGameMode = #cursor then
  421.       pCursorX = (pCursorLoc[pLocNum][1] - pCursorLoc[pLocNum - 1][1]) / 70.0
  422.       pCursorY = (pCursorLoc[pLocNum][2] - pCursorLoc[pLocNum - 1][2]) / 70.0
  423.       put pCursorX, pCursorY
  424.       pCursorX2 = 0
  425.       pCursorY2 = 0
  426.       if pActionNum = 4 then
  427.         pCamRotate = 1
  428.         pt = w3d.camera[1].overlay[2].loc
  429.         pMousePrevX = pt[1]
  430.         pMousePrevY = pt[2]
  431.         pRotX = 0
  432.         pRotY = 0
  433.       end if
  434.     end if
  435.   end if
  436. end
  437.  
  438. on insAction
  439.   setVariable(sprite(1), "insAction", pInsAction[pInsNum])
  440.   pInsNum = pInsNum + 1
  441.   pActionNum = pActionNum + 1
  442.   gGameMode = pActions[pActionNum]
  443.   if gGameMode = #waitAction then
  444.     pWaitStart = the timer
  445.   end if
  446. end
  447.  
  448. on moveCursor
  449.   t = (the milliSeconds - pCursorTime) / 20.0
  450.   put t
  451.   pt = w3d.camera[1].overlay[2].loc
  452.   arrived = 0
  453.   if ((pCursorX > 0) and (pt[1] >= pCursorLoc[pLocNum][1])) or ((pCursorX < 0) and (pt[1] <= pCursorLoc[pLocNum][1])) then
  454.     arrived = arrived + 1
  455.   else
  456.     if pCursorX < 1 then
  457.       pCursorX2 = pCursorX2 + (pCursorX * t)
  458.       if (pCursorX2 > 1) or (pCursorX2 < -1) then
  459.         pt[1] = pt[1] + pCursorX2
  460.         pCursorX2 = 0
  461.       end if
  462.     else
  463.       pt[1] = pt[1] + (pCursorX * t)
  464.     end if
  465.   end if
  466.   if ((pCursorY > 0) and (pt[2] >= pCursorLoc[pLocNum][2])) or ((pCursorY < 0) and (pt[2] <= pCursorLoc[pLocNum][2])) then
  467.     arrived = arrived + 1
  468.   else
  469.     if pCursorY < 1 then
  470.       pCursorY2 = pCursorY2 + (pCursorY * t)
  471.       if (pCursorY2 > 1) or (pCursorY2 < -1) then
  472.         pt[2] = pt[2] + pCursorY2
  473.         pCursorY2 = 0
  474.       end if
  475.     else
  476.       pt[2] = pt[2] + (pCursorY * t)
  477.     end if
  478.   end if
  479.   if arrived = 2 then
  480.     w3d.camera[1].overlay[2].loc = pCursorLoc[pLocNum]
  481.     pLocNum = pLocNum + 1
  482.     pActionNum = pActionNum + 1
  483.     gGameMode = pActions[pActionNum]
  484.     if gGameMode = #waitAction then
  485.       pWaitStart = the timer
  486.     end if
  487.     if pCamRotate then
  488.       pCamRotate = 0
  489.     end if
  490.     put "arrived @ " & pActionNum
  491.   else
  492.     w3d.camera[1].overlay[2].loc = pt
  493.   end if
  494.   if pCamRotate then
  495.     pRotX = (pt[1] - pMousePrevX) * 0.5
  496.     pRotY = (pt[2] - pMousePrevY) * 0.5
  497.     pMousePrevX = pt[1]
  498.     pMousePrevY = pt[2]
  499.     if pRotX > 10 then
  500.       pRotX = 10
  501.     else
  502.       if pRotX < -10 then
  503.         pRotX = -10
  504.       end if
  505.     end if
  506.     if pRotY > 10 then
  507.       pRotY = 10
  508.     else
  509.       if pRotY < -10 then
  510.         pRotY = -10
  511.       end if
  512.     end if
  513.   end if
  514. end
  515.  
  516. on changePipe
  517.   pPipeActive.shaderList[getShaderNum(pPipeActive)] = pNormalShader
  518.   pPipeActive = pPipes[3]
  519.   pPipeActive.shaderList[getShaderNum(pPipeActive)] = pGlowShader
  520.   setArrows()
  521.   soundFX("choose", 3, 100)
  522.   pActionNum = pActionNum + 1
  523.   gGameMode = pActions[pActionNum]
  524.   if gGameMode = #waitAction then
  525.     pWaitStart = the timer
  526.   end if
  527. end
  528.  
  529. on movePipe
  530.   if pActionNum < 20 then
  531.     pPipeActive.worldPosition = pArrow[3].worldPosition
  532.   else
  533.     pPipeActive.worldPosition = pArrow[4].worldPosition
  534.   end if
  535.   setArrows()
  536.   soundFX("click", 3, 50)
  537.   pActionNum = pActionNum + 1
  538.   gGameMode = pActions[pActionNum]
  539.   if gGameMode = #waitAction then
  540.     pWaitStart = the timer
  541.   end if
  542. end
  543.  
  544. on checkDrop
  545.   pos = pBall.worldPosition
  546.   vel = pBallRB.linearVelocity.magnitude
  547.   sound(2).volume = vel
  548.   if vel < 5 then
  549.     pStuckCount = pStuckCount + 1
  550.   else
  551.     pStuckCount = 0
  552.   end if
  553.   repeat with p in pPipes
  554.     dPipe = pos.distanceTo(p.worldPosition)
  555.     ps = p.shaderList[getShaderNum(p)].name
  556.     if (dPipe < 10) and (ps = "GlassShader") then
  557.       soundFX("light", 3, 100)
  558.       pPipesUsed = pPipesUsed + 1
  559.       p.shaderList[getShaderNum(p)] = pGlowShader
  560.     end if
  561.   end repeat
  562.   if gSkillMode > 1 then
  563.     repeat with p in pGap
  564.       dGap = pos.distanceTo(p)
  565.       if dGap < 10 then
  566.         pLevelFailure = 1
  567.       end if
  568.     end repeat
  569.   end if
  570.   dCup = pos.distanceTo(pCup.worldPosition)
  571.   if dCup < 12 then
  572.     pLandCount = pLandCount + 1
  573.   end if
  574.   if (pLandCount > 0) and (pLandCount < 50) then
  575.     dy = pos.y - pCup.worldPosition.y
  576.     if dy < 0 then
  577.       soundFX("land", 3, 100)
  578.       sound(2).stop()
  579.       pLandCount = 50
  580.     end if
  581.   end if
  582.   if pLandCount > 70 then
  583.     pFadeState = #down
  584.     gGameMode = #finish
  585.   end if
  586.   dy = pCup.worldPosition.y - pos.y
  587.   if (dy > 500) or (pStuckCount > 100) then
  588.     pLevelFailure = 1
  589.     pFadeState = #down
  590.     gGameMode = #finish
  591.   end if
  592. end
  593.  
  594. on setArrows
  595.   repeat with i = 1 to 6
  596.     pArrow[i].transform.position = vector(0, 1000, 0)
  597.   end repeat
  598.   arrowNum = 1
  599.   p = pPipeActive.worldPosition
  600.   if gLevel < 31 then
  601.     upperLimit = 33
  602.   else
  603.     upperLimit = 49
  604.   end if
  605.   repeat with i in pAdjSlots
  606.     pos = p + i
  607.     if (pos.x < upperLimit) and (pos.x > -1) and (pos.y < 1) and (pos.y > -upperLimit) and (pos.z < 1) and (pos.z > -upperLimit) then
  608.       blocked = 0
  609.       repeat with b in pPipes
  610.         d = (pos - b.worldPosition).magnitude
  611.         if d < 1 then
  612.           blocked = 1
  613.         end if
  614.       end repeat
  615.       repeat with b in pBoxes
  616.         d = (pos - b.worldPosition).magnitude
  617.         if d < 1 then
  618.           blocked = 1
  619.         end if
  620.       end repeat
  621.       if not blocked then
  622.         pArrow[arrowNum].transform.position = pos
  623.         pArrow[arrowNum].translate(0.01, 0.01, 0.01)
  624.         pArrow[arrowNum].pointAt(p + (i * 2), vector(0, 1, 0))
  625.         pArrow[arrowNum].transform.position = pos
  626.         arrowNum = arrowNum + 1
  627.       end if
  628.     end if
  629.   end repeat
  630. end
  631.  
  632. on fadeLevel
  633.   f = cam.overlay[1].blend
  634.   if pFadeState = #up then
  635.     if f > 0 then
  636.       cam.overlay[1].blend = f - 5
  637.     else
  638.       cam.overlay[1].blend = 0
  639.       pFadeState = #none
  640.     end if
  641.   else
  642.     if pFadeState = #down then
  643.       if f < 100 then
  644.         cam.overlay[1].blend = f + 5
  645.       else
  646.         cam.overlay[1].blend = 100
  647.         pFadeState = #none
  648.         endOfLevel()
  649.       end if
  650.     end if
  651.   end if
  652. end
  653.  
  654. on endOfLevel
  655.   repeat with i = 1 to 8
  656.     sound(i).stop()
  657.   end repeat
  658.   go(the frame + 1)
  659. end
  660.  
  661. on setupCamera
  662.   cam = w3d.camera[1]
  663.   cam.fieldOfView = 50
  664.   dcam = w3d.newModel("dummyCam")
  665.   dcamCenter = w3d.newModel("dummyCenter")
  666.   if gLevel < 31 then
  667.     dcamCenter.transform.position = vector(16, -16, -16)
  668.     pCamZoom = 60
  669.   else
  670.     dcamCenter.transform.position = vector(24, -24, -24)
  671.     pCamZoom = 80
  672.   end if
  673.   dcamCenter.addChild(dcam, #preserveParent)
  674.   dcam.translate(-pCamZoom, 0, -pCamZoom)
  675.   pRotX = 0
  676.   pRotY = 0
  677. end
  678.  
  679. on updateCamera
  680.   dcam.transform.position.z = pCamZoom
  681.   dcam.transform.position.x = pCamZoom
  682.   if pCamRotate then
  683.     dcamCenter.rotate(0, -pRotX, 0)
  684.     dcam.rotate(dcamCenter.worldPosition, vector(0, 0, 1), -pRotY * 2, #self)
  685.   end if
  686.   if abs(dcam.worldPosition.y + 16) > 85 then
  687.     dcam.rotate(dcamCenter.worldPosition, vector(0, 0, 1), pRotY * 2.20000000000000018, #self)
  688.   end if
  689.   dcam.pointAt(dcamCenter.worldPosition, vector(0, 1, 0))
  690.   camBuffer = 20
  691.   cam.transform.interpolateTo(dcam.getWorldTransform(), camBuffer)
  692. end
  693.  
  694. on endSprite me
  695.   hk.shutDown()
  696.   w3d.resetWorld()
  697. end
  698.